var mySource = {
    // 查看模板
    viewSource: '',
    // 修改模板
    modifySource: '',
    // 列表模板
    listSource: '',
    // 页面结构
    viewHead: '',
    modifyHead: '',
    listHead: '',
    content: '',
    viewFoot: '',
    modifyFoot: '',
    listFoot: '',
    viewScript: '',
    modifyScript: '',
    listScript: '',
    // 后台模版
    endingSource: ''
};

/**
 * 页面头部
 */
mySource.viewHead = (function () {
    return '<!DOCTYPE html>'
        + '<html xmlns="http://www.w3.org/1999/xhtml">'
        + '<head>'
        + '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'
        + '<meta name="viewport" content="width=device-width, initial-scale=1.0" />'
        + '<title></title>'
        + '<!-- Bootstrap core CSS -->'
        + '<link href="../css/bootstrap.min.css" rel="stylesheet" />'
        + '<link href="../css/bootstrap-reset.css" rel="stylesheet" />'
        + '<!--external css-->'
        + '<link href="../assets/font-awesome/css/font-awesome.css" rel="stylesheet" />'
        + '<!-- Custom styles for this template -->'
        + '<link href="../css/style.css" rel="stylesheet" />'
        + '<link href="../css/style-responsive.css" rel="stylesheet" />'
        + '<link href="../assets/toastr-master/toastr.css" rel="stylesheet" />'
        + '<!-- HTML5 shim and Respond.js IE8 support of HTML5 tooltipss and media queries -->'
        + '<!--[if lt IE 9]>'
        + '<script src="../js/html5shiv.js"></script>'
        + '<script src="../js/respond.min.js"></script>'
        + '<![endif]-->'
        + '</head>'
        + '<body>'
        + '<section class="wrapper site-min-height">';
})();

mySource.modifyHead = (function () {
    return '<!DOCTYPE html>'
        + '<html xmlns="http://www.w3.org/1999/xhtml">'
        + '<head>'
        + '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'
        + '<meta name="viewport" content="width=device-width, initial-scale=1.0" />'
        + '<title></title>'
        + '<!-- Bootstrap core CSS -->'
        + '<link href="../css/bootstrap.min.css" rel="stylesheet" />'
        + '<link href="../css/bootstrap-reset.css" rel="stylesheet" />'
        + '<!--external css-->'
        + '<link href="../assets/font-awesome/css/font-awesome.css" rel="stylesheet" />'
        + '<!-- Custom styles for this template -->'
        + '<link href="../css/style.css" rel="stylesheet" />'
        + '<link href="../css/style-responsive.css" rel="stylesheet" />'
        + '<link href="../assets/toastr-master/toastr.css" rel="stylesheet" />'
        + '<!-- 按需加载 -->'
        + '<link rel="stylesheet" href="/scripts/blockui/blockUI.css" />'
        + '<link rel="stylesheet" type="text/css" href="/scripts/datepicker/css/bootstrap-datepicker3.min.css" />'
        + '<!-- HTML5 shim and Respond.js IE8 support of HTML5 tooltipss and media queries -->'
        + '<!--[if lt IE 9]>'
        + '<script src="../js/html5shiv.js"></script>'
        + '<script src="../js/respond.min.js"></script>'
        + '<![endif]-->'
        + ' <style>'
        + '    .form-horizontal .control-label {'
        + '        text-align: right;'
        + '    }'
        + ' </style>'
        + '</head>'
        + '<body>'
        + '<section class="wrapper site-min-height">';
})();

mySource.listHead = (function () {
    return '<!DOCTYPE html>'
        + '<html xmlns="http://www.w3.org/1999/xhtml">'
        + '<head>'
        + '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'
        + '<meta name="viewport" content="width=device-width, initial-scale=1.0" />'
        + '<title></title>'
        + '<!-- Bootstrap core CSS -->'
        + '<link href="../css/bootstrap.min.css" rel="stylesheet" />'
        + '<link href="../css/bootstrap-reset.css" rel="stylesheet" />'
        + '<!--external css-->'
        + '<link href="../assets/font-awesome/css/font-awesome.css" rel="stylesheet" />'
        + '<!-- Custom styles for this template -->'
        + '<link href="../css/style.css" rel="stylesheet" />'
        + '<link href="../css/style-responsive.css" rel="stylesheet" />'
        + '<link href="../assets/toastr-master/toastr.css" rel="stylesheet" />'
        + '<!-- 按需加载 -->'
        + '<link rel="stylesheet" href="/scripts/blockui/blockUI.css" />'
        + '<link rel="stylesheet" href="../css/jquery.dataTables.css" />'
        + '<link rel="stylesheet" type="text/css" href="/scripts/datepicker/css/bootstrap-datepicker3.min.css" />'
        + '<!-- HTML5 shim and Respond.js IE8 support of HTML5 tooltipss and media queries -->'
        + '<!--[if lt IE 9]>'
        + '<script src="../js/html5shiv.js"></script>'
        + '<script src="../js/respond.min.js"></script>'
        + '<![endif]-->'
        + '<!-- style 2784行 修改，对齐datatables左下角 info 和 length'
        + 'dataTables_length, .dataTables_filter {'
        + 'adding: 0 0 15px;'
        + '}'
        + '-->'
        + '</head>'
        + '<body>'
        + '<section class="wrapper site-min-height">';
})();

/**
 * 页面内容部分
 */
mySource.content = (function () {
    return '';
})();

/**
 * 页面尾部
 */
mySource.viewFoot = (function () {
    return '</section>'
        + '<!-- js placed at the end of the document so the pages load faster -->'
        + '<script src="/js/jquery.js"></script>'
        + '<script src="/js/bootstrap.min.js"></script>'
        + '<script src="/assets/toastr-master/toastr.js"></script>'
        + '<!-- 按需加载 -->'
        + '<script type="text/javascript" src="/scripts/util/myUtil2.js"></script>'
        + '<script type="text/javascript" src="/scripts/myJsPlugin/viewPlugin.js"></script>';
})();

mySource.modifyFoot = (function () {
    return '</section>'
        + '<!-- js placed at the end of the document so the pages load faster -->'
        + '<script src="/js/jquery.js" type="text/javascript"></script>'
        + '<script src="/js/bootstrap.min.js" type="text/javascript"></script>'
        + '<script src="/assets/toastr-master/toastr.js" type="text/javascript"></script>'
        + '<!-- 按需加载 -->'
        + '<script src="/scripts/datepicker/scripts/bootstrap-datepicker.min.js" type="text/javascript"></script>'
        + '<script src="/scripts/maxlength/bootstrap-maxlength.min.js" type="text/javascript"></script>'
        + '<script src="/scripts/select2/select2.full.min.js" type="text/javascript"></script>'
        + '<script src="/scripts/blockui/jquery.blockUI.js" type="text/javascript"></script>'
        + '<script src="/scripts/util/myUtil2.js" type="text/javascript"></script>'
        + '<script src="/scripts/myJsPlugin/modifyPlugin.js" type="text/javascript"></script>';
})();

mySource.listFoot = (function () {
    return '</section>'
        + '<!-- js placed at the end of the document so the pages load faster -->'
        + '<script src="/js/jquery.js" type="text/javascript"></script>'
        + '<script src="/js/bootstrap.min.js" type="text/javascript"></script>'
        + '<script src="/assets/toastr-master/toastr.js" type="text/javascript"></script>'
        + '<!-- 按需加载 -->'
        + '<script src="/scripts/datepicker/scripts/bootstrap-datepicker.min.js" type="text/javascript"></script>'
        + '<script src="/scripts/datatables/jquery.dataTables.js" type="text/javascript"></script>'
        + '<script src="/scripts/datatables/dataTables.bootstrap.js" type="text/javascript"></script>'
        + '<script src="/scripts/util/myUtil2.js" type="text/javascript"></script>'
        + '<script src="/scripts/myJsPlugin/listPlugin.js" type="text/javascript"></script>';
})();

/**
 * 详情页面模板
 */
mySource.viewSource = (function () {
    "use strict";
    return '<!-- page start-->'
        + '<div class="col-xs-12">'
        + '    <section class="panel panel-primary">'
        + '        <header class="panel-heading">'
        + '            <i class="fa fa-search"></i>'
        + '           {{moduleName}}详情</header>'
        + '        <div class="panel-body">'
        + '            <form class="form-horizontal" role="form">'
        + '                <div class="form-body">'
        + '                    <!--/row-->'
        + '                    <div class="row">'
        + '{{each fieldList as item i}}'
        + '                        <div class="col-md-6">'
        + '                            <div class="form-group">'
        + '                                <label class="control-label col-md-3">{{item.name}}:</label>'
        + '                               <div class="col-md-9">'
        + '                                   <p class="form-control-static" id="{{item.id}}"></p>'
        + '                               </div>'
        + '                           </div>'
        + '                        </div>'
        + '                         {{if (i+1)%2 ===0}}'
        + '                         </div><!--/row--><div class="row">'
        + '                         {{/if}}'
        + '{{/each}}'
        + '                    </div>'
        + '                </div>'
        + '                <div class="form-actions">'
        + '                     <div class="row">'
        + '                     <div class="col-md-offset-4 col-md-8">'
        + '                     <button id="btnReturn" type="button" class="btn btn-warning">'
        + '                     <i class="fa fa-reply"></i>返回</button>'
        + '                     </div>'
        + '                     </div>'
        + '                </div>'
        + '            </form>'
        + '        </div>'
        + '    </section>'
        + '</div>'
        + '<!-- page end-->';
}());


/**
 * 编辑页面模板
 */
mySource.modifySource = (function () {
    "use strict";
    return '<!-- page start-->'
        + '        <div class="col-lg-12">'
        + '            <section class="panel panel-primary">'
        + '                <header class="panel-heading">'
        + '                    <i class="fa fa-search"></i>'
        + '                    {{moduleName}}添加</header>'
        + '                <div class="panel-body">'
        + '                <form class="form-horizontal" role="form" id="myForm">'
        + '                    <div class="form-body">'
        + '                    <!--/row-->'
        + '                    <div class="row">'
        + '{{each fieldList as item i}}'
        + '                        <div class="col-md-12">'
        + '                        <div class="form-group">'
        + '                            <label class="col-md-3 control-label">{{item.name}}：{{if item.requiredMsg !==""}}<span class="text-danger">*</span>{{/if}}</label>'
        + '{{if item.type==="input"}}'
        + '                            <div class="col-md-4">'
        + '                                <input id="{{item.id}}" name="{{item.id}}" type="text" class="form-control maxlength_input" placeholder="{{item.placeholder}}" maxlength="{{item.maxlength}}" />'
        + '{{else if item.type==="select"}}'
        + '                            <div class="col-md-4">'
        + '                                 <select class="form-control" id="{{item.id}}" name="{{item.id}}">'
        + '                                 </select>'
        + '{{else if item.type==="time"}}'
        + '                            <div class="col-md-4">'
        + '                                 <div class="input-group date form_datetime" data-date="">'
        + '                                     <input type="text" size="16" class="form-control" id="{{item.id}}" name="{{item.id}}">'
        + '										<span class="input-group-btn">'
        + '										<button class="btn default date-set" type="button"><i'
        + '                                            class="fa fa-calendar"></i></button>'
        + '										</span>'
        + '                                 </div>'
        + '{{else if item.type==="textarea"}}'
        + '                            <div class="col-md-9">'
        + '                               <textarea id="{{item.id}}" name="{{item.id}}" class="form-control" maxlength="{{item.maxlength}}" rows="4"'
        + '                                          placeholder="{{item.placeholder}}"></textarea>'
        + '{{else if item.type==="fileinput"}}'
        + '{{/if}}'
        + '                             {{if item.direcation !==""}}<span class="help-block">{{item.direcation}}</span>{{/if}}'
        + '                             </div>'
        + '                         {{if (i+1)%2 ===0}}'
        + '                         </div><!--/row--><div class="row">'
        + '                         {{/if}}'
        + '{{/each}}'
        + '                    </div>'
        + '                </div>'
        + '                            <div class="form-actions">'
        + '                               <div class="row">'
        + '                                         <div class="col-md-offset-4 col-md-8">'
        + '                                             <button id="btnSubmit" type="button" class="btn btn-info">'
        + '                                                 <i class="fa fa fa-pencil-square-o"></i>提交</button>'
        + '                                             <button id="btnReturn" type="button" class="btn btn-warning">'
        + '                                                 <i class="fa fa-reply"></i>返回</button>'
        + '                                         </div>'
        + '                               </div>'
        + '                            </div>'
        + '                </form>'
        + '                </div>'
        + '            </section>'
        + '        </div>'
        + '    <!-- page end-->';
}());


/**
 * 列表页面模板
 */
mySource.listSource = (function () {
    "use strict";
    return '<!-- page start-->'
        + '    <div class="col-lg-12">'
        + '        <section class="panel panel-primary">'
        + '            <header class="panel-heading">'
        + '                <i class="fa fa-filter"></i>查询内容<span class="tools pull-right">'
        + '                <button class="btn btn-success btn-sm"><i class="fa fa-filter"></i>搜索</button>'
        + '                <button class="btn btn-default btn-sm"><i class="fa fa-undo"></i>重置</button>'
        + '            </span>'
        + '           </header>'
        + '            <div class="panel-body">'
        + '                <form class="form-horizontal" role="form">'
        + '                    <div class="row">'
        + '{{each fieldList as item i}}'
        + '{{if item.isSearch==="Y"}}'
        + '                           <div class="col-md-4">'
        + '                                <div class="form-group">'
        + '                                    <label class="control-label col-md-3">{{item.name}}</label>'
        + '                                    <div class="col-md-9">'
        + '                                    {{if item.type==="input"}}'
        + '                                        <input id="{{item.id}}Search" type="text" class="form-control" placeholder="{{item.placeholder}}">'
        + '                                    {{else if item.type==="select"}}'
        + '                                        <select id="{{item.id}}Search" class="form-control"></select>'
        + '                                    {{else if item.type==="time"}}'
        + '                                        <div class="input-group input-daterange range_datetime" id="">'
        + '                                            <input type="text" class=" form-control" readonly="" id="timeStart" name="timeStart">'
        + '                                            <span class="input-group-addon">到</span>'
        + '                                            <input type="text" class=" form-control" readonly="" id="timeEnd" name="timeEnd">'
        + '                                        </div>'
        + '                                    {{/if}}'
        + '                                    </div>'
        + '                                </div>'
        + '                            </div>'
        + '{{/if}}'
        + '{{/each}}'
        + '                     </div>'
        + '                  </form>'
        + '             </div>'
        + '        </section>'
        + '        <section class="panel panel-primary">'
        + '            <header class="panel-heading">'
        + '            <i class="fa fa-cogs"></i>数据列表<span class="tools pull-right">'
        + '                <button id="btnAdd" class="btn btn-primary btn-sm"><i class="fa fa-plus"></i>新增</button>'
        + '                <button class="btn btn-info btn-sm"><i class="fa fa-pencil-square-o"></i>编辑</button>'
        + '                <button class="btn btn-danger btn-sm"><i class="fa fa-trash-o"></i>删除</button>'
        + '                <button class="btn btn-success btn-sm"><i class="fa fa-search"></i>查看</button>'
        + '                <button class="btn btn-warning btn-sm"><i class="fa fa-refresh"></i>刷新</button>'
        + '                <button class="btn btn-info btn-sm"><i class="fa fa-file-text-o"></i>导入</button>'
        + '            </span>'
        + '                       </header>'
        + '                        <div class="panel-body">'
        + '                            <section>'
        + '                               <table class="table table-striped table-hover table-bordered" id="myDataTable">'
        + '                                    <thead>'
        + '                                    <tr>'
        + '{{each fieldList as item i}}'
        + '                                     {{if item.isShowColumn ==="Y"}}'
        + '                                        <th>{{item.name}}</th>'
        + '                                     {{/if}}'
        + '{{/each}}'
        + '                                        <th>操作</th>'
        + '                                    </tr>'
        + '                                    </thead>'
        + '                                    <tbody>'
        + '                                    </tbody>'
        + '                                </table>'
        + '                            </section>'
        + '                        </div>'
        + '                    </section>'
        + '                </div>'
        + '                <!-- page end-->';
}());

/**
 * javascript模板
 */
mySource.viewScript = (function () {
    "use strict";
    return '<script>'
        + '$(document).ready(function () {\r\n'
        + '    \'use strict\';\r\n'
        + '    // 配置插件\r\n'
        + '    var myViewPlugin = new ViewPlugin({\r\n'
        + '        // 处理程序url\r\n'
        + '        handlerUrl: \'handler/{{moduleID}}Handler.ashx\',\r\n'
        + '        // 返回页面url\r\n'
        + '        returnPageUrl\: \'{{moduleID}}_list.aspx?state=has\',\r\n'
        + '        // 获取详情额外参数\r\n'
        + '        viewParams: {\r\n'
        + '            action: \'detail\',\r\n'
        + '            id: myUtil.getUrlParam(\'id\')\r\n'
        + '        },\r\n'
        + '        // 页面控件\r\n'
        + '        pageControls: [\r\n'
        + '            //{\r\n'
        + '                //controlID: \'#userName\',\r\n'
        + '                // 赋值需要特殊处理的，添加reset属性，element指这个$(\'#userName\')对象，value是值\r\n'
        + '                //reset: function (element, value) {\r\n'
        + '                    //return \'<span class="danger">\' + value + \'</span>\';\r\n'
        + '                //}\r\n'
        + '            //},\r\n'
        + '{{each fieldList as item i}}'
        + '            {\r\n'
        + '                controlID: \'#{{item.id}}\'\r\n'
        + '            },\r\n'
        + '{{/each}}'
        + '        ]\r\n'
        + '    });\r\n'
        + '\r\n'
        + '    // 重写单击事件绑定(默认有返回按钮事件)\r\n'
        + '    //myViewPlugin.bindClickEvent = function () {\r\n'
        + '    //    $(\'#btnReturn\').on(\'click\', function () {\r\n'
        + '    //        window.self.location.href = \'user_list.aspx?state=has\';\r\n'
        + '    //    });\r\n'
        + '    //};\r\n'
        + '\r\n'
        + '    // 初始化插件\r\n'
        + '    myViewPlugin.init();\r\n'
        + '});\r\n'
        + '</script>'
        + '</body>'
        + '</html>';
}());

/**
 * modifyScript模板
 */
mySource.modifyScript = (function () {
    "use strict";
    return '<script>'
        + '$(document).ready(function () {\r\n'
        + '    \'use strict\';\r\n'
        + '    // 配置插件\r\n'
        + '    var myModifyPlugin = new ModifyPlugin({\r\n'
        + '        // id\r\n'
        + '        id: myUtil.getUrlParam(\'id\'),\r\n'
        + '        //  处理程序url\r\n'
        + '        handlerUrl: \'handler/{{moduleID}}Handler.ashx\',\r\n'
        + '        // 获取详情额外参数\r\n'
        + '        viewParams: {\r\n'
        + '            action: \'detail\',\r\n'
        + '            id: myUtil.getUrlParam(\'id\')\r\n'
        + '        },\r\n'
        + '        // 提交数据额外参数\r\n'
        + '        submitParams: {\r\n'
        + '            action: \'submit\',\r\n'
        + '            id: myUtil.getUrlParam(\'id\')\r\n'
        + '        },\r\n'
        + '        // 返回页面url\r\n'
        + '        returnPageUrl: \'{{moduleID}}_list.aspx?state=has\',\r\n'
        + '        // 输入控件\r\n'
        + '        pageControls: [\r\n'
        + '{{each fieldList as item i}}'
        + '            {\r\n'
        + '                controlID: \'#{{item.id}}\',\r\n'
        + '                requiredMsg: \'{{item.requiredMsg}}！\'\r\n'
        + '            },\r\n'
        + '{{/each}}'
        + '        ]\r\n'
        + '\r\n'
        + '    });\r\n'
        + '\r\n'
        + '    // 重写单击事件绑定(默认有返回按钮事件)\r\n'
        + '    //myModifyPlugin.bindClickEvent = function () {\r\n'
        + '    //    $(\'#btnReturn\').on(\'click\', function () {\r\n'
        + '    //        window.self.location.href = \'user_list.aspx?state=has\';\r\n'
        + '    //    });\r\n'
        + '    //};\r\n'
        + '\r\n'
        + '    // 初始化插件\r\n'
        + '    myModifyPlugin.init();\r\n'
        + '});\r\n'
        + '</script>'
        + '</body>'
        + '</html>';
}());

/**
 * listScript模板
 */
mySource.listScript = (function () {
    "use strict";
    return '<script>'
    + '$(document).ready(function () {\r\n'
    + '    \'use strict\';\r\n'
    + '    // 配置插件\r\n'
    + '    var myListPlugin = new ListPlugin({\r\n'
    + '        // 处理程序url\r\n'
    + '        handlerUrl: \'handler/{{moduleID}}Handler.ashx\',\r\n'
    + '        // 获取列表额外参数\r\n'
    + '        listParams: {\r\n'
    + '            action: \'list\',\r\n'
    + '{{each fieldList as item i}}'
    + '{{if item.isSearch === Y}}'
    + '            {{item.id}}: $(\'#{{item.id}}\').val(),\r\n'
    + '{{/if}}'
    + '{{/each}}'
    + '        },\r\n'
    + '        // 列\r\n'
    + '        columns: [\r\n'
    + '{{each fieldList as item i}}'
    + '{{if item.isShowColumn === "Y"}}'
    + '            {\r\n'
    + '               data: \'{{item.id}}\'\r\n'
    + '            },\r\n'
    + '{{/if}}'
    + '{{/each}}'
    + '        ],\r\n'
    + '        // 行绘制回调函数\r\n'
    + '        rowCallback: function (row, data, index) {\r\n'
    + '        },\r\n'
    + '        // 行创建回调函数\r\n'
    + '        createdRow: function (row, data, dataIndex) {\r\n'
    + '            var html = \'<button class="btn btn-xs btn-success btnRowView"><i class="fa fa-search">查看</i></button>\';\r\n'
    + '            html += \'  <button class="btn btn-xs btn-info btnRowEdit"><i class="fa fa-pencil-square-o">编辑</i></button>\';\r\n'
    + '            html += \'  <button class="btn btn-xs btn-danger btnRowDelete"><i class="fa fa-trash-o">删除</i></button>\';\r\n'
    + '            $(\'td:last\', row).html(html);\r\n'
    + '        },\r\n'
    + '        // 表格重绘回调函数\r\n'
    + '        drawCallback: function (settings) {\r\n'
    + '            //$("#checkall").prop("checked", false);\r\n'
    + '        },\r\n'
    + '        // 表格初始化结束后回调函数\r\n'
    + '        initCompleteOther: function (settings, json, myDataTable) {\r\n'
    + '            // 给最后一列按钮添加点击事件\r\n'
    + '            // 查看\r\n'
    + '            $(\'#myDataTable tbody\').on(\'click\', \'.btnRowView\', function () {\r\n'
    + '                var data = myDataTable.row($(this).parents(\'tr\')).data();\r\n'
    + '                window.self.location.href = \'{{moduleID}}_view.aspx?id=\' + data.id;\r\n'
    + '            });\r\n'
    + '\r\n'
    + '            // 编辑\r\n'
    + '            $(\'#myDataTable tbody\').on(\'click\', \'.btnRowEdit\', function () {\r\n'
    + '                var data = myDataTable.row($(this).parents(\'tr\')).data();\r\n'
    + '                window.self.location.href = \'{{moduleID}}_modify.aspx?id=\' + data.id;\r\n'
    + '            });\r\n'
    + '\r\n'
    + '            // 删除\r\n'
    + '            $(\'#myDataTable tbody\').on(\'click\', \'.btnRowDelete\', function () {\r\n'
    + '                var data = myDataTable.row($(this).parents(\'tr\')).data();\r\n'
    + '\r\n'
    + '                myUtil.blockUI({\r\n'
    + '                    target: \'#myDataTable\',\r\n'
    + '                    message: \'删除中，请稍等...\'\r\n'
    + '                });\r\n'
    + '\r\n'
    + '                $.when($.ajax({\r\n'
    + '                    url: \'handler/{{moduleID}}Handler.ashx\',\r\n'
    + '                    type: \'post\',\r\n'
    + '                    data: {\r\n'
    + '                        action: \'delete\',\r\n'
    + '                        id: data.id\r\n'
    + '                    },\r\n'
    + '                   dataType: \'json\'\r\n'
    + '                })).done(function (data) {\r\n'
    + '                    toastr.success(\'删除成功！\');\r\n'
    + '                    // 刷新表格\r\n'
    + '                    myDataTable.ajax.reload();\r\n'
    + '                }).always(function () {\r\n'
    + '                    myUtil.unblockUI(\'#myDataTable\');\r\n'
    + '                });\r\n'
    + '            });\r\n'
    + '        }\r\n'
    + '    });\r\n'
    + '\r\n'
    + '    // 重写单击事件绑定\r\n'
    + '    myListPlugin.bindClickEvent = function () {\r\n'
    + '        // 添加按钮事件\r\n'
    + '        $(\'#btnAdd\').on(\'click\', function () {\r\n'
    + '            window.self.location.href = \'{{moduleID}}_modify.aspx?state=has\';\r\n'
    + '        });\r\n'
    + '\r\n'
    + '    };\r\n'
    + '\r\n'
    + '    // 重写其他事件绑定\r\n'
    + '    myListPlugin.bindOtherEvent = function () {\r\n'
    + '        // 日期范围控件\r\n'
    + '        $(\'.range_datetime\').datepicker({\r\n'
    + '            format: \'yyyy-mm-dd\',\r\n'
    + '            todayBtn: \'linked\',\r\n'
    + '            clearBtn: true,\r\n'
    + '            language: \'zh-CN\',\r\n'
    + '            autoclose: true,\r\n'
    + '            todayHighlight: true,\r\n'
    + '            toggleActive: true\r\n'
    + '        });\r\n'
    + '    };\r\n'
    + '\r\n'
    + '    // 初始化插件\r\n'
    + '    myListPlugin.init();\r\n'
    + '\r\n'
    + '});\r\n'
    + '</script>'
    + '</body>'
    + '</html>';
}());

/**
 * 后台模板
 */
mySource.endingSource = (function () {
    "use strict";
    return ''
        + ' using Newtonsoft.Json;\r\n'
        + ' using System;\r\n'
        + ' using System.Collections.Generic;\r\n'
        + ' using System.Data;\r\n'
        + ' using System.Linq;\r\n'
        + ' using System.Text;\r\n'
        + ' using System.Web;\r\n'
        + ' using System.Web.SessionState;\r\n'
        + ' using System.Data.SqlClient;\r\n'
        + ' using Maticsoft.DBUtility;\r\n'
        + '\r\n'
        + 'namespace \r\n'
        + '{\r\n'
        + '    /// <summary>\r\n'
        + '    /// {{moduleID}}Handler 的摘要说明\r\n'
        + '    /// </summary>\r\n'
        + '    public class {{moduleID}} : IHttpHandler, IRequiresSessionState\r\n'
        + '    {\r\n'
        + '        // 创建对象\r\n'
        + '        BLL.{{className}} bll = new BLL.{{className}}();\r\n'
        + '        public void ProcessRequest(HttpContext context)\r\n'
        + '        {\r\n'
        + '            context.Response.ContentType = "text/plain";\r\n'
        + '\r\n'
        + '            // 结果\r\n'
        + '            string result = "";\r\n'
        + '            string action = context.Request["action"];\r\n'
        + '\r\n'
        + '            // 判断动作\r\n'
        + '            switch (action)\r\n'
        + '            {\r\n'
        + '                // 列表\r\n'
        + '                case "list":\r\n'
        + '                    result = list(context);\r\n'
        + '                    break;\r\n'
        + '                // 提交\r\n'
        + '                case "submit":\r\n'
        + '                    if (string.IsNullOrWhiteSpace(context.Request["id"]))\r\n'
        + '                    {\r\n'
        + '                        result = add(context);\r\n'
        + '                    }\r\n'
        + '                    else\r\n'
        + '                    {\r\n'
        + '                        result = edit(context);\r\n'
        + '                    }\r\n'
        + '                    break;\r\n'
        + '                // 详情\r\n'
        + '                case "detail":\r\n'
        + '                    result = detail(context);\r\n'
        + '                    break;\r\n'
        + '                // 删除\r\n'
        + '                case "delete":\r\n'
        + '                    result = delete(context);\r\n'
        + '                    break;\r\n'
        + '                default:\r\n'
        + '                    break;\r\n'
        + '            }\r\n'
        + '\r\n'
        + '            // 输出结果\r\n'
        + '            context.Response.Write(result);\r\n'
        + '        }\r\n'
        + '\r\n'
        + '        /// <summary>\r\n'
        + '        /// 列表\r\n'
        + '        /// </summary>\r\n'
        + '        /// <param name="context"></param>\r\n'
        + '        /// <returns></returns>\r\n'
        + '        private string list(HttpContext context)\r\n'
        + '        {\r\n'
        + '            // 反馈结果\r\n'
        + '            string result = "{\\"errMsg\\":\\"\\"}";\r\n'
        + '\r\n'
        + '            try\r\n'
        + '            {\r\n'
        + '                // 接受参数\r\n'
        + '{{each fieldList as item i}}'
        + '{{if item.isSearch === Y}}'
        + '                string {{item.id}} = context.Request["{{item.id}}"];\r\n'
        + '{{/if}}'
        + '{{/each}}'
        + '\r\n'
        + '                // where条件\r\n'
        + '                string strWhere = " 1=1";\r\n'
        + '                string dtEnd = context.Request["dtEnd"];\r\n'
    + '                string dtBegin = context.Request["dtBegin"];\r\n'
    + '{{each fieldList as item i}}'
    + '{{if item.isSearch === Y}}'
    + '                if (!string.IsNullOrWhiteSpace({{item.id}}))\r\n'
    + '                {\r\n'
    + '                    strWhere += " and {{item.id}} =\'" + {{item.id}} + "\'";\r\n'
    + '                }\r\n'
    + '{{/if}}'
    + '{{/each}}'
    + '                if (!string.IsNullOrWhiteSpace(dtBegin))\r\n'
    + '                {\r\n'
    + '                    strWhere += " and  CONVERT(VARCHAR(10), reporttime,120) >=\'" + dtBegin + "\'";\r\n'
    + '                }\r\n'
    + '                if (!string.IsNullOrWhiteSpace(dtEnd))\r\n'
    + '                {\r\n'
    + '                    strWhere += " and  CONVERT(VARCHAR(10), reporttime,120) <=\'" + dtEnd + "\'";\r\n'
    + '                }\r\n'
    + '                if (!string.IsNullOrWhiteSpace(isDelete))\r\n'
    + '                {\r\n'
    + '                    strWhere += " and isDelete=\'N\'";\r\n'
    + '                }\r\n'
    + '\r\n'
    + '                // 分页相关参数\r\n'
    + '                int draw = int.Parse(context.Request["draw"]);\r\n'
    + '                int length = int.Parse(context.Request["length"]);\r\n'
    + '                int start = int.Parse(context.Request["start"]);\r\n'
    + '                int pageIndex = start / length + 1;\r\n'
    + '\r\n'
    + '                // 获取数据\r\n'
    + '                int count = bll.GetRecordCount(strWhere); // 总数据条数\r\n'
    + '                DataSet ds = bll.GetListByPage(strWhere, "id desc", start, pageIndex * length);\r\n'
    + '                List<Model.{{className}}> list = bll.DataTableToList(ds.Tables[0]);\r\n'
    + '\r\n'
    + '                // 遍历数据\r\n'
    + '                List<My{{moduleID}}Model> myList = new List<My{{moduleID}}Model>();\r\n'
    + '\r\n'
    + '                foreach (var item in list)\r\n'
    + '                {\r\n'
    + '                    // 创建model\r\n'
    + '                    My{{moduleID}}Model myModel = new My{{moduleID}}Model\r\n'
    + '                    {\r\n'
    + '                        id = item.id.ToString(),\r\n'
    + '{{each fieldList as item i}}'
    + '                            {{item.id}} = item.{{item.id}}.ToString(),\r\n'
    + '{{/each}}'
    + '                    };\r\n'
    + '\r\n'
    + '                    // 循环push\r\n'
    + '                    myList.Add(myModel);\r\n'
    + '                }\r\n'
    + '\r\n'
    + '                // 创建listmodel\r\n'
    + '                My{{moduleID}}ListModel myListModel = new My{{moduleID}}ListModel\r\n'
    + '                {\r\n'
    + '                    draw = draw,\r\n'
    + '                    recordsTotal = count,\r\n'
    + '                    recordsFiltered = count,\r\n'
    + '                    data = myList\r\n'
    + '                };\r\n'
    + '\r\n'
    + '                // 序列化\r\n'
    + '                result = JsonConvert.SerializeObject(myListModel);\r\n'
    + '            }\r\n'
    + '            catch (Exception ex)\r\n'
    + '            {\r\n'
    + '                // 添加错误日志\r\n'
    + '                //rf_common.logger_error(ex.ToString(), HttpContext.Current);\r\n'
    + '                result = "{\\"errMsg\\":\\"添加失败," + ex.Message + "\\"}";\r\n'
    + '            }\r\n'
    + '\r\n'
    + '            return result;\r\n'
    + '        }\r\n'
    + '\r\n'
    + '        /// <summary>\r\n'
    + '        /// 添加\r\n'
    + '        /// </summary>\r\n'
    + '        /// <param name="context"></param>\r\n'
    + '        /// <returns></returns>\r\n'
    + '        private string add(HttpContext context)\r\n'
    + '        {\r\n'
    + '            // 反馈结果\r\n'
    + '            string result = "{\\"errMsg\\":\\"\\"}";\r\n'
    + '\r\n'
    + '            try\r\n'
    + '            {\r\n'
    + '                // 接受参数\r\n'
    + '{{each fieldList as item i}}'
    + '                string {{item.id}} = context.Request["{{item.id}}"];\r\n'
    + '{{/each}}'
    + '\r\n'
    + '                // 创建model\r\n'
    + '                Model.{{className}} model = new Model.{{className}}\r\n'
    + '                {\r\n'
    + '{{each fieldList as item i}}'
    + '{{if item.type === "time"}}'
    + '                    {{item.id}} = DateTime.Parse({{item.id}}),\r\n'
    + '{{else}}'
    + '                    {{item.id}} = {{item.id}},\r\n'
    + '{{/if}}'
    + '{{/each}}'
    + '                };\r\n'
    + '\r\n'
    + '                // 执行操作\r\n'
    + '                if (bll.Add(model) <= 0)\r\n'
    + '                {\r\n'
    + '                    result = "{\\"errMsg\\":\\"添加失败\\"}";\r\n'
    + '                }\r\n'
    + '            }\r\n'
    + '            catch (Exception ex)\r\n'
    + '            {\r\n'
    + '                // 添加错误日志\r\n'
    + '                //rf_common.logger_error(ex.ToString(), HttpContext.Current);\r\n'
    + '                result = "{\\"errMsg\\":\\"添加失败," + ex.Message + "\\"}";\r\n'
    + '            }\r\n'
    + '\r\n'
    + '            return result;\r\n'
    + '        }\r\n'
    + '\r\n'
    + '        /// <summary>\r\n'
    + '        /// 编辑\r\n'
    + '        /// </summary>\r\n'
    + '        /// <param name="context"></param>\r\n'
    + '        /// <returns></returns>\r\n'
    + '        private string edit(HttpContext context)\r\n'
    + '        {\r\n'
    + '            // 反馈结果\r\n'
    + '            string result = "{\\"errMsg\\":\\"\\"}";\r\n'
    + '\r\n'
    + '            try\r\n'
    + '            {\r\n'
    + '                // 接受参数\r\n'
    + '                string id = context.Request["id"];\r\n'
    + '{{each fieldList as item i}}'
    + '                string {{item.id}} = context.Request["{{item.id}}"];\r\n'
    + '{{/each}}'
    + '\r\n'
    + '                // 通过ID获取数据\r\n'
    + '                Model.{{className}} model = bll.GetModel(int.Parse(id));\r\n'
    + '\r\n'
    + '                if (model != null)\r\n'
    + '                {\r\n'
    + '{{each fieldList as item i}}'
    + '{{if item.type === "time"}}'
    + '                    model.{{item.id}} = DateTime.Parse({{item.id}}),\r\n'
    + '{{else}}'
    + '                    model.{{item.id}} = {{item.id}};\r\n'
    + '{{/if}}'
    + '{{/each}}'
    + '\r\n'
    + '                    // 执行操作\r\n'
    + '                    if (bll.Update(model) == false)\r\n'
    + '                    {\r\n'
    + '                        result = "{\\"errMsg\\":\\"更新失败\\"}";\r\n'
    + '                    }\r\n'
    + '                }\r\n'
    + '            }\r\n'
    + '            catch (Exception ex)\r\n'
    + '            {\r\n'
    + '                // 添加错误日志\r\n'
    + '                //rf_common.logger_error(ex.ToString(), HttpContext.Current);\r\n'
    + '                result = "{\\"errMsg\\":\\"更新失败," + ex.Message + "\\"}";\r\n'
    + '            }\r\n'
    + '\r\n'
    + '            return result;\r\n'
    + '        }\r\n'
    + '\r\n'
    + '        /// <summary>\r\n'
    + '        /// 详情\r\n'
    + '        /// </summary>\r\n'
    + '        /// <param name="context"></param>\r\n'
    + '        /// <returns></returns>\r\n'
    + '        private string detail(HttpContext context)\r\n'
    + '        {\r\n'
    + '            // 反馈结果\r\n'
    + '            string result = "{\\"errMsg\\":\\"\\"}";\r\n'
    + '\r\n'
    + '            try\r\n'
    + '            {\r\n'
    + '                // 接受参数\r\n'
    + '                string id = context.Request["id"];\r\n'
    + '\r\n'
    + '                // 通过ID获取数据\r\n'
    + '                Model.{{className}} model = bll.GetModel(int.Parse(id));\r\n'
    + '\r\n'
    + '                if (model != null)\r\n'
    + '                {\r\n'
    + '                    // 创建model\r\n'
    + '                    My{{moduleID}}Model myModel = new My{{moduleID}}Model\r\n'
    + '                    {\r\n'
    + '                        id = model.id.ToString(),\r\n'
    + '{{each fieldList as item i}}'
    + '                            {{item.id}} = model.{{item.id}}.ToString(),\r\n'
    + '{{/each}}'
    + '\r\n'
    + '                    };\r\n'
    + '\r\n'
    + '                    // 序列化\r\n'
    + '                    result = JsonConvert.SerializeObject(myModel);\r\n'
    + '                }\r\n'
    + '\r\n'
    + '            }\r\n'
    + '            catch (Exception ex)\r\n'
    + '            {\r\n'
    + '                // 添加错误日志\r\n'
    + '                //rf_common.logger_error(ex.ToString(), HttpContext.Current);\r\n'
    + '                result = "{\\"errMsg\\":\\"获取详情失败," + ex.Message + "\\"}";\r\n'
    + '            }\r\n'
    + '\r\n'
    + '            return result;\r\n'
    + '        }\r\n'
    + '\r\n'
    + '        /// <summary>\r\n'
    + '        /// 删除\r\n'
    + '        /// </summary>\r\n'
    + '        /// <param name="context"></param>\r\n'
    + '        /// <returns></returns>\r\n'
    + '        private string delete(HttpContext context)\r\n'
    + '        {\r\n'
    + '            string result = "{\\"errMsg\\":\\"\\"}";\r\n'
    + '\r\n'
    + '            try\r\n'
    + '            {\r\n'
    + '                string id = context.Request["id"];\r\n'
    + '\r\n'
    + '                if (bll.Delete(int.Parse(id)) == false)\r\n'
    + '                {\r\n'
    + '                    result = "{\\"errMsg\\":\\"删除失败\\"}";\r\n'
    + '                }\r\n'
    + '            }\r\n'
    + '            catch (Exception ex)\r\n'
    + '            {\r\n'
    + '                // 添加错误日志\r\n'
    + '                //rf_common.logger_error(ex.ToString(), HttpContext.Current);\r\n'
    + '                result = "{\\"errMsg\\":\\"删除失败," + ex.Message + "\\"}";\r\n'
    + '            }\r\n'
    + '            return result;\r\n'
    + '        }\r\n'
    + '\r\n'
    + '\r\n'
    + '        public bool IsReusable\r\n'
    + '        {\r\n'
    + '            get\r\n'
    + '            {\r\n'
    + '                return false;\r\n'
    + '            }\r\n'
    + '        }\r\n'
    + '    }\r\n'
    + '\r\n'
    + '    public struct My{{moduleID}}ListModel\r\n'
    + '    {\r\n'
    + '        public int draw;\r\n'
    + '        public int recordsTotal;\r\n'
    + '        public int recordsFiltered;\r\n'
    + '        public List<My{{moduleID}}Model> data;\r\n'
    + '    }\r\n'
    + '\r\n'
    + '    public struct My{{moduleID}}Model\r\n'
    + '    {\r\n'
    + '       public string id;\r\n'
    + '{{each fieldList as item i}}'
    + '        public string {{item.id}};\r\n'
    + '{{/each}}'
    + '    }\r\n'
    + '}\r\n'
    + '';
}());
